package com.hbmcc.rxjava.chapter01

import android.os.Bundle
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.VirtualLayoutManager
import com.hbmcc.rxjava.R
import com.hbmcc.rxjava.annotation.ClazzInfo
import com.hbmcc.rxjava.base.TitleActivity
import com.hbmcc.rxjava.chapter01.adapter.ProxyBannerAdapter
import java.util.*

/**
 * 创建日期：2020/11/3
 * 描述:Tangram 基础用法
 * 作者:支豪亮
 */




@ClazzInfo(1, 1, "第一小节", "vlayout 基础用法")
class Tangram0102Activity : TitleActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)
        initView()
    }

    private fun initView() {
        val recyclerView: RecyclerView = findViewById(R.id.rclTest)
        val layoutManager = VirtualLayoutManager(this)
        recyclerView.layoutManager = layoutManager


        val delegateAdapter = DelegateAdapter(layoutManager, true)
        recyclerView.adapter = delegateAdapter

        val viewPool = RecyclerView.RecycledViewPool()
        recyclerView.setRecycledViewPool(viewPool)

        // recyclerView.addItemDecoration(itemDecoration);
        viewPool.setMaxRecycledViews(R.layout.view_pager_item, 20)

        val adapters: MutableList<DelegateAdapter.Adapter<*>> = LinkedList()
        adapters.add(ProxyBannerAdapter(R.layout.view_pager, viewPool))
        delegateAdapter.setAdapters(adapters)
    }
}